package com.example.aspect;

import com.example.annotation.Xuxin;


import org.aopalliance.aop.Advice;
import org.springframework.aop.Pointcut;
import org.springframework.aop.support.AbstractPointcutAdvisor;
import org.springframework.aop.support.ComposablePointcut;
import org.springframework.aop.support.annotation.AnnotationMatchingPointcut;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Component;

@Component
public class XuxinAdvisor extends AbstractPointcutAdvisor {
    private final Advice advice;
    private final Pointcut pointcut;

    public XuxinAdvisor() {
        this.advice = new XuxinInterceptor();
        Pointcut p1 = new AnnotationMatchingPointcut(null, Xuxin.class);
        Pointcut p2 = new AnnotationMatchingPointcut(Xuxin.class, null);
        this.pointcut = new ComposablePointcut(p1).union(p2);
//        this.pointcut = new ComposablePointcut(p1);
    }

    @Override
    @NonNull
    public Pointcut getPointcut() {
        return pointcut;
    }

    @Override
    @NonNull
    public Advice getAdvice() {
        return advice;
    }
}
